package com.maben.s9002.controller;

import com.maben.s9002.pojo.Role;
import com.maben.s9002.service.RoleService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("role")
public class RoleController {
    @Resource
    private RoleService roleService;

    @GetMapping("queryRoleList")
    public List<Role> queryRoleList()throws Exception{
        return roleService.list();
    }

    @PostMapping("saveRole")
    public void saveRole(String name)throws Exception{
        final Role user = new Role();
        user.setName(name);
        roleService.saveRole(user);
    }

    /**
     * 测试mybatis-plus原生写入方法
     */
    @PostMapping("saveRole2")
    public void saveRole2(String name)throws Exception{
        final Role user = new Role();
        user.setName(name);
        roleService.save(user);
    }
}
